package gui;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.geom.Arc2D;
import java.awt.geom.Area;

/**
 * @author Ramy Refky 
 * */
public class XorComponentLabel extends ComponentLabel{

	private static final long serialVersionUID = 1L;
	
	/**
	 * Constructor initializes ComponentLabel.
	 * @param XLocation, YLocation, Width, Height
	 */
	public XorComponentLabel(int xLoc,int yLoc,int originalWidth, int originalHeight){
		super(xLoc,yLoc,originalWidth,originalHeight);
	}
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		
		Shape arc = new Arc2D.Float((float) (-newWidth*0.1),1,(float) (newWidth*0.3),newHeight-3,-90,180, Arc2D.OPEN);
		Shape arc4 = new Arc2D.Float((float) (-newWidth*0.18),1,(float) (newWidth*0.3),newHeight-3,-90,180, Arc2D.OPEN);
		
		Shape arc2 = new Arc2D.Float(-newWidth*10/15,2,(float) (newWidth*1.5),newHeight-4,-90,90, Arc2D.OPEN);
		Shape arc3 = new Arc2D.Float(-newWidth*10/15,2,(float) (newWidth*1.5),newHeight-4,90,-90, Arc2D.OPEN);
		
		Point p1 = new Point(8,1);
		Point p2 = new Point(8,newHeight-1);
		Point p3 = new Point((int) (newWidth*0.85),newHeight/2);

		int[] xs = { p1.x, p2.x, p3.x };
		int[] ys = { p1.y, p2.y, p3.y };
		Polygon triangle = new Polygon(xs, ys,3);
		
		Area shape = new Area(triangle);
		shape.subtract(new Area(arc));
		shape.add(new Area(arc2));
		shape.add(new Area(arc3));
		
    	Graphics2D g2 = (Graphics2D)g;
    	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);
    	
        g2.setStroke(new BasicStroke(4f));
        g2.setPaint(Color.black);
       
        g2.draw(arc);
        g2.draw(arc2);
        g2.draw(arc3);
        g2.setStroke(new BasicStroke(2f));
        g2.draw(arc4);
        
        if(!selected)
        	g2.setPaint(Color.white);
        else
        	g2.setPaint(Color.getHSBColor((float)0.5,(float)0.1,(float)0.9));
     
        g2.fill(shape);
	}
}
